﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Departments;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.OrderShow
{
    /// <summary>
    /// 部门下拉
    /// </summary>
    public class DepartmentShowHandler : IRequestHandler<DepartmentShowCommend, Result>
    {
        private readonly IBaseRepositoryGet<Department> Department;

        public DepartmentShowHandler(IBaseRepositoryGet<Department> Department)
        {
            this.Department = Department;
        }

        public async Task<Result> Handle(DepartmentShowCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

            string sql = "SELECT * FROM Department";
            var list = Department.GetAll(sql, default).ToList();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }

            return result;
        }
    }
}
